package com.chushouya.manager.constants;


import com.general.framework.core.enums.IEnum;
import com.general.framework.core.exception.Ex;
import com.general.framework.core.lang.Lists;
import com.general.framework.core.lang.Strings;

import java.util.List;
import java.util.Objects;

/**
 * 结算业务类型
 */
public enum SettleBizInAndOutEnum implements IEnum<Integer> {

    IN(1, "收入", Lists.asList(
            SettleBizTypeEnum.STORE_COMMISSION.value(),
            SettleBizTypeEnum.MERCHANT_RECHARGE.value()
    )),
    OUT(-1, "支出", Lists.asList(
            SettleBizTypeEnum.STORE_WITHDRAW.value(),
            SettleBizTypeEnum.MERCHANT_WITHDRAW.value(),
            SettleBizTypeEnum.COMMERCE_RECYCLE_DEDUCT.value()
    ))
    ;

    private Integer inOrOut;

    private String desc;

    private List<Integer> bizTypes;

    SettleBizInAndOutEnum(Integer inOrOut, String desc, List<Integer> bizTypes) {
        this.inOrOut = inOrOut;
        this.desc = desc;
        this.bizTypes = bizTypes;
    }

    public static String getDesc(Integer bizTypeSimple) {
        for (SettleBizInAndOutEnum thisEnum : SettleBizInAndOutEnum.values()) {
            if (Objects.equals(thisEnum.inOrOut, bizTypeSimple)) {
                return thisEnum.desc;
            }
        }
        return Strings.EMPTY;
    }

    public static SettleBizInAndOutEnum get(Integer bizTypeSimple) {
        for (SettleBizInAndOutEnum thisEnum : SettleBizInAndOutEnum.values()) {
            if (Objects.equals(thisEnum.inOrOut, bizTypeSimple)) {
                return thisEnum;
            }
        }
        throw Ex.systemError("未定义的结算类型[{}]", bizTypeSimple);
    }

    public static Integer getInOrOut(Integer bizType) {
        return SettleBizInAndOutEnum.IN.getBizTypes().contains(bizType) ? SettleBizInAndOutEnum.IN.value() : SettleBizInAndOutEnum.OUT.value();
    }

    @Override
    public Integer value() {
        return this.inOrOut;
    }

    @Override
    public String named() {
        return this.desc;
    }

    public List<Integer> getBizTypes() {
        return bizTypes;
    }
}
